package com.bqtt.tumor.demo.business;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bqtt.tumor.demo.common.MyBeanFactory;
import com.bqtt.tumor.demo.data_access.TreatmentMethodDAO;
import com.bqtt.tumor.demo.entity.DiagnosisMethod;
import com.bqtt.tumor.demo.entity.Feature;
import com.bqtt.tumor.demo.entity.TreatmentMethod;

public class TreatmentMethodService {

	
	private static TreatmentMethodDAO treatmentMethodDAO = (TreatmentMethodDAO) MyBeanFactory.getBean("treatmentMethodDAO");
	private static Logger log = LoggerFactory.getLogger(TreatmentMethodService.class);
	
	public static List<TreatmentMethod> searchByCondition(TreatmentMethod condition,int pageSize,int pageNo)
	{
		
		List<TreatmentMethod> result = treatmentMethodDAO.fuzzyFindByProperties(condition.getSQLValidAttributes(),pageSize,pageNo);

		return result;
	}
	
	public static List<TreatmentMethod> getList()
	{
		return treatmentMethodDAO.findAll();
	}
	
	
	public static List<TreatmentMethod> getMethodsByIds(List<Integer> ids)
	{
		List<TreatmentMethod>  result = new ArrayList<TreatmentMethod>();
		
		for(Integer item:ids)
		{
			result.add(treatmentMethodDAO.findById(item));
		}
		return result;
	}
	
	
	public static TreatmentMethod getMethodById(int id)
	{
		return treatmentMethodDAO.findById(id);
	}
	
	public static List<TreatmentMethod> searchByCondition(TreatmentMethod condition,int pageSize,int pageNo,long id)
	{
		
		List<TreatmentMethod> result = treatmentMethodDAO.fuzzyFindByProperties(condition.getSQLValidAttributes(),pageSize,pageNo);
		
		for(TreatmentMethod item:result)
		{
			if(item.getTreatment_method_def_id()==id)
			{
				item.setDisplayName("inline-block");
			}
			item.fillStringField();
		}
		return result;
	}
	
	public static boolean add(TreatmentMethod obj)
	{
		try
		{
			treatmentMethodDAO.save(obj);
			return true;
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
	     	return false;	
		}
		
	}
	
	public static boolean update(TreatmentMethod obj)
	{
		try
		{
			 
			if(obj.getTreatment_method_def_id()>0)
			{
				treatmentMethodDAO.update(obj);
				return true;
			}
			else
				
			return false;
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
	     	return false;	
		}
		
	}
}
